<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>货物配送系统</title>
<%-- <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.4.2.min.js"></script> --%>

<style type="text/css">
table {
	margin: 0 auto;
}

#article {
	border: 1px solid #EEDC82;
	height: 450px;
}

#button {
	width: 252px;
	height: 30px;
	padding-left: 0;
	font-size: 15px;
}

th {
	width: 180px;
	height: 40px;
	background-color: #F9D16B;
	font-size: 18px;
	font-weight: normal;
}

tr {
	text-align: center;
}

[type='checkbox'] {
	width: 30px;
	height: 30px;
}

[type='button'] {
	width: 100px;
	height: 30px;
}

#button {
	width: 252px;
	height: 30px;
	padding-left: 0;
	font-size: 15px;
}

#p{
		color: #1166EE;
		
		
	}
	#p1{
		height: 60px;
		background-image:url("${pageContext.request.contextPath }/Images/borrow_if.gif");
		background-repeat: no-repeat;
	}
</style>
</head>
<body style="font-size:20px">
	<%@ include file="navigation.jsp"%>
	<div id="article">
	<p id="p"> 当前位置：门店管理 > 门店负责人设置>> </p>	
	   <div id="d1">
	       <p id="p1"></p>
		   <input id="button" type="button" onclick="window.location='${pageContext.request.contextPath}/systemSet/user_edit'" value="添加用户信息">
		<table>
			<tr>
				<th>管理员名称</th>
				<th>门店管理</th>
				<th>车辆管理</th>
				<th>仓库管理</th>
				<th>订单管理</th>
				<th>商品管理</th>
<%--				<c:if test="${manager.id}">--%>
					<th>权限设置</th>
<%--				</c:if>--%>
<%--				<c:if test="${manager.id}">--%>
					<th>操作</th>
<%--				</c:if>--%>
			</tr>

			<c:forEach items="${purviews}" var="p">
				<tr>
					<td><input type="hidden" value="${p.id}"><input
						type="hidden" value="${p.admin}">${p.admin}</td>
					<!-- 判断系统设置 -->
					<c:choose>
						<c:when test="${p.sysset==1}">
							<td><input type="checkbox" name="sysset" checked="checked"></td>
						</c:when>
						<c:otherwise>
							<td><input type="checkbox" name="sysset"></td>
						</c:otherwise>
					</c:choose>
					<c:choose>
						<c:when test="${p.readerset==1}">
							<td><input type="checkbox" name="readerset"
								checked="checked"></td>
						</c:when>
						<c:otherwise>
							<td><input type="checkbox" name="readerset"></td>
						</c:otherwise>
					</c:choose>

					<c:choose>
						<c:when test="${p.bookset==1}">
							<td><input type="checkbox" name="bookset" checked="checked"></td>
						</c:when>
						<c:otherwise>
							<td><input type="checkbox" name="bookset"></td>
						</c:otherwise>
					</c:choose>
					<c:choose>
						<c:when test="${p.borrowback==1}">
							<td><input type="checkbox" name="borrowback"
								checked="checked"></td>
						</c:when>
						<c:otherwise>
							<td><input type="checkbox" name="borrowback"></td>
						</c:otherwise>
					</c:choose>
					<c:choose>
						<c:when test="${p.sysquery==1}">
							<td><input type="checkbox" name="sysquery" checked="checked"></td>
						</c:when>
						<c:otherwise>
							<td><input type="checkbox" name="sysquery"></td>
						</c:otherwise>
					</c:choose>
<%--					&& manager.id==1--%>
					<c:if test="${p.id !=1 }">
						<td><input type="button" value="修改" class="mod"></td>
					</c:if>
<%--					manager.id==1 &&--%>
					<!--如果该用户ID为1则显示删除按钮 -->
					<c:if test="${ p.id!=1}">
						<td><input type="button" value="删除" class="del"></td>
					</c:if>
				</tr>
			</c:forEach>
		 </table>
	  </div>
	</div>

</body>
<script type="text/javascript">
	$(function() {
		disabledAll();
		$("#tianjia").click(function () {
			var url="/user_edit";
			$


		});

		$(".mod").click(function() {
			if (this.value == "修改") {
				bind(this, true);
				this.value = "保存";
			} else {
				/* 提交ajax */

				bind(this, false);
				bindAJAX(this);
				this.value = "修改";
			}
		});

		/* 根据ID删除管理员的AJAX */
		$(".del").click(function() {
			/* 得到ID */
			var c = $($(this).parent().siblings()[0]);
			var id = c.children()[0].value;
			/* 			$.ajax({
			 url:"deleteById.do",
			 data:{"id":id},
			 type:"post",
			 dataType:"json",
			 }); */
			$.post("deleteById.do", {
				"id" : id
			}, function() {
				alert("提交成功！");
				location.reload();
			});

		});

	});

	/* 设置隐藏属性 */
	function bind(t, flag) {
		$(t).parent().siblings().children("input:checkbox").each(function() {
			if (flag) {
				$(this).removeAttr("disabled");
			} else {
				$(this).attr("disabled", "disabled");
			}
		});
	}
	/*隐藏全部*/
	function disabledAll() {
		$("input:checkbox").each(function() {
			$(this).attr("disabled", "disabled");
		});
	}

	function bindAJAX(t) {

		$.post("updatePurview.do", {
			id : $(t).parent().siblings().children("input:hidden")
					.attr("value"),
			sysset : getAtt(t, "sysset"),
			readerset : getAtt(t, "readerset"),
			bookset : getAtt(t, "bookset"),
			borrowback : getAtt(t, "borrowback"),
			sysquery : getAtt(t, "sysquery")
		},
		/* 回调函数 */
		function() {
			alert("提交成功！");
		});
	}

	function getAtt(t, attrName) {
		var result;
		$(t).parent().siblings().children("input:checkbox").each(function() {
			if (attrName == $(this).attr("name")) {
				result = $(this).attr("checked");
				return;
			}
		});
		return result ? 1 : 0;
	}
</script>
</html>


